package cn.lml.lession.config;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.lml.lession.util.SessionUtils;

@Configuration
public class ApplicationConfig implements WebMvcConfigurer {

	
	@Bean
	public ServletListenerRegistrationBean<HttpSessionListener> customSessionListener() {
		ServletListenerRegistrationBean<HttpSessionListener> customSessionListener = new ServletListenerRegistrationBean<HttpSessionListener>();
		customSessionListener.setListener(new HttpSessionListener() {
			@Override
			public void sessionCreated(HttpSessionEvent se) {
				HttpSession session = se.getSession();
				SessionUtils.addSession(session);
			}

			@Override
			public void sessionDestroyed(HttpSessionEvent se) {
				HttpSession session = se.getSession();
				SessionUtils.delSession(session);
			}
		});
		return customSessionListener;
	}
}
